package com.hdey.controller.max;



import com.hdey.pojo.max.TbUscWarehouse;
import com.hdey.service.max.TbUscWarehouseSvs;
import com.hdey.utils.Result;
import com.hdey.vo.WarehouseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/wareHouse")
@Slf4j
public class TbUscWarehouseController {

    @Resource
    private TbUscWarehouseSvs warehouseSvs;

    private String msg;

    @RequestMapping("/getTbUscWarehouse")
    public Result getTbUscWarehouse(){
        List<WarehouseVo> list = warehouseSvs.getTbUscWarehouse();
        return Result.success(list);
    }

    @RequestMapping("/updateTbUscWarehouse")
    public Result updateTbUscWarehouse(@RequestBody TbUscWarehouse house){
        int result = warehouseSvs.updateTbUscWarehouse(house);
        if(result > 0){
            msg = "修改成功！";
        }else{
            msg = "系统错误！";
        }
        return Result.success(msg);
    }


    @RequestMapping("/createTbUscWarehouse")
    public Result createTbUscWarehouse(@RequestBody TbUscWarehouse house){
        int result = warehouseSvs.createTbUscWarehouse(house);
        if(result > 0){
            msg = "添加成功！";
        }else{
            msg = "系统错误！";
        }
        return Result.success(msg);
    }


    @RequestMapping("/getTbUscWarehouseByBranch")
    public Result getTbUscWarehouseByBranch(String branch){
        List<TbUscWarehouse> list = warehouseSvs.getTbUscWarehouseByBranch(branch);
        return Result.success(list,list.size());
    }


}
